﻿namespace RandomGame
{
    internal class Program
    {
        static void Main(string[] args)
        {
            //确定测试总次数
            Console.WriteLine("请键入您想测试的次数并敲击回车键以开始");
            int nOfGame = Convert.ToInt32(Console.ReadLine());
            double reacttionTime = 0;
            int nOfError = 0;
            DateTime begin = DateTime.Now;
            for (int i = 1; i <=nOfGame; i++)
            {
                DateTime end = DateTime.Now;
                reacttionTime=(end-begin).TotalSeconds;
                Console.WriteLine($"总耗时为{reacttionTime},错误次数为{nOfError}");
                Console.WriteLine($"这是第{i}次测试，请快速敲击屏幕上显示的字母");
                //随机生成26个字母的大小写字符
                //随机生成1或2，分别代表大写和小写
                int ASCII = 0;
                Random ra = new Random();
                int RA = ra.Next(1, 3);
                //小写
                if (RA==1)
                {
                    Random character = new Random();
                    ASCII = character.Next(97, 123);
                }
                //大写
                else if (RA==2)
                {
                    Random character = new Random();
                    ASCII = character.Next(65, 91);
                }
                //显示字母
                Console.Write(Convert.ToChar(ASCII));
                int input = Convert.ToInt32(Console.ReadKey().KeyChar);
                Console.Clear();
                //输入正确
                if (input==ASCII)
                {
                    continue;
                }
                //输入错误
                else if (input!=ASCII)
                {
                    nOfError++;
                    continue;
                }
            }
            DateTime endl = DateTime.Now;
            reacttionTime=(endl-begin).TotalSeconds;
            Console.WriteLine($"总耗时为{reacttionTime},错误次数为{nOfError}");
        }
    }
}